﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dao;

namespace Web.Page
{
    public partial class CS_DZQY_Edit : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.lblTitle.Text = "修改DZQY";
                initValue();
            }
        }

        private void initValue()
        {
            this.tbBH.Text = Request.QueryString["bh"];
            this.tbMC.Text = Request.QueryString["mc"];
            this.tbBZ.Text = Request.QueryString["bz"];
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ClearControlsValue();
        }

        /// <summary>
        /// 清空所有TextBox内容
        /// </summary>
        private void ClearControlsValue()
        {
            this.lbResult.Text = "";
            this.tbMC.Text = "";
            this.tbBZ.Text = "";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.lbResult.Text = "";
            if (this.tbBH.Text.Trim().Equals(""))
            {
                this.lbResult.Text = "请输入编号";
                return;
            }
            if (this.tbMC.Text.Trim().Equals(""))
            {
                this.lbResult.Text = "请输入名称";
                return;
            }

            CS_DZQY entity = new CS_DZQY()
            {
                BH = tbBH.Text.Trim(),
                MC = tbMC.Text.Trim(),
                BZ = tbBZ.Text.Trim()
            };

            string resultMessage = "";
            try
            {
                CS_DZQY_Dao dao = new CS_DZQY_Dao();
                int result = dao.Update(entity);

                if (result == 1)
                {
                    resultMessage = "修改成功";
                    ClearControlsValue();
                }
            }
            catch (Exception ex)
            {
                resultMessage = "修改失败:" + ex.Message;
            }
            finally
            {
                this.lbResult.Text = resultMessage;
            }
        }
    }
}